package com.amigo.online.message.controller;

import com.amigo.online.common.core.security.IgnoreSecurity;
import com.amigo.online.message.entity.ChatMessage;
import com.amigo.online.message.service.MessageCallbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 消息回调
 */
@RestController
@RequestMapping("callback")
public class MessageCallbackController {

    @Autowired
    MessageCallbackService callbackService;


    /**
     * 由小米MIMC服务回调("即时消息")
     */
    @IgnoreSecurity
    @RequestMapping(value = "callback" , method = RequestMethod.POST)
    public void callback(@RequestBody ChatMessage singleChatMessage){
        try {
            callbackService.callback(singleChatMessage);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    /**
     * 由小米MIMC服务回调("离线消息")
     */
    @IgnoreSecurity
    @RequestMapping(value = "offlineCallback" ,method = RequestMethod.POST)
    public void offlineCallback(@RequestBody ChatMessage singleChatMessage){
        callbackService.callback(singleChatMessage);
    }
}
